﻿using Quartz;
using Quartz.Impl;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ezCloud.SendEmailMarketingBySchedule.Job
{
    public class JobScheduler
    {
        public static void Start()
        {
            IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
            scheduler.Start();

            IJobDetail jobEmail = JobBuilder.Create<EmailJob>().Build();
            IJobDetail jobTemplate = JobBuilder.Create<CreateTemplateEmailJob>().Build();

            ITrigger triggerTemplate = TriggerBuilder.Create()
                .WithDailyTimeIntervalSchedule
                  (s =>
                     s.OnEveryDay()
                    .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(2, 0))
                  )
                .Build();

            ITrigger triggerEmail = TriggerBuilder.Create()
                .WithDailyTimeIntervalSchedule
                  (s =>
                     s.WithIntervalInMinutes(5)
                    .OnEveryDay()
                    .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(8, 0))
                  )
                .Build();

            scheduler.ScheduleJob(jobEmail, triggerEmail);
            scheduler.ScheduleJob(jobTemplate, triggerTemplate);
        }
    }
}